/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.hutech09.jsale.web.manager.customer;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import org.hutech09.jsale.bsn.ICustomerManager;
import org.hutech09.jsale.bsn.exception.ItemExistsException;
import org.hutech09.jsale.entity.Customer;
import org.hutech09.jsale.web.manager.model.LazyCustomerDataModel;

/**
 *
 * @author Nam
 */
@ManagedBean
@SessionScoped
public class CustomerBrowseCtrl {

    @EJB
    private ICustomerManager customerManager;

    @ManagedProperty("#{orderBrowseCtrl}")
    private OrderBrowseCtrl orderBrowse;

    private Customer selected = new Customer();

    private LazyCustomerDataModel dataModel;

    @PostConstruct
    public void init() {
        dataModel = new LazyCustomerDataModel(customerManager);
    }

    public OrderBrowseCtrl getOrderBrowse() {
        return orderBrowse;
    }

    public void setOrderBrowse(OrderBrowseCtrl orderBrowse) {
        this.orderBrowse = orderBrowse;
    }

    public Customer getSelected() {
        return selected;
    }

    public void setSelected(Customer selected) {
        this.selected = selected;
        orderBrowse.setCustomer(selected);
    }

    public LazyCustomerDataModel getDataModel() {
        return dataModel;
    }

    public void setDataModel(LazyCustomerDataModel dataModel) {
        this.dataModel = dataModel;
    }

    public void delete() {
    }

    public void genCustomer() {
//        Customer cus = new Customer();
//        cus.setId("nam");
//        cus.setEmail("nam@mgail.com");
//        cus.setAddress("Gò vấp");
//        cus.setSkype("nam.nguyentu");
//        cus.setPassword("132");
//        cus.setPhone("0013133");
//        try {
//            customerManager.create(cus);
//        } catch (ItemExistsException ex) {
//            Logger.getLogger(CustomerBrowseCtrl.class.getName()).log(Level.SEVERE, null, ex);
//        }
    }

    public void sendMail() {
//        customerManager.sendMyMail();
    }
}
